import  { defineConfig, type ConfigEnv, type UserConfigExport,loadEnv} from 'vite'

import vue from '@vitejs/plugin-vue'

import { viteMockServe } from 'vite-plugin-mock'
// @ts-ignore
import path from "path";

// https://vite.dev/config/
export default ({ command,mode }: ConfigEnv):UserConfigExport => {
  //@ts-ignore
  const env = loadEnv(mode,process.cwd())
  return {
    plugins: [
      vue(),
      viteMockServe({
        localEnabled: command === 'serve',
      })
    ],
    resolve: {
      alias: {
        "@": path.resolve("./src")//相对路径别名设置
      }
    },
    server:{
      proxy:{
        [env.VITE_APP_BASE_API]:{
          target:env.VITE_APP_SERVICE_URL,
          changeOrigin:true,
          rewrite:(path)=>path.replace(/^\/dev-api/,'')
        }
      }
    }
  }
}